package com.su.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ModBusCommand {

@Autowired
private SocketForModBus socketForModBus;

    // 0x10 Write Multiple registers
    public boolean infrared(String host, int port, String addressCode, String value) {
        SocketForModBus.SDU sdu = new SocketForModBus.SDU(host, port);
        // combine SDU(host, port, ADU)
        ModBus.ADU adu = new ModBus.ADU();
        adu.setAddress(addressCode);
        ModBus.ADU.PDU pdu = new ModBus.ADU.PDU(value);
        adu.setPdu(pdu);
        sdu.setAdu(adu);
        System.out.println("sdu = " + sdu);
        List<Integer> list = socketForModBus.perform(sdu);
        return Parse.ofWrite(list);
    }








}
